package scau.erps.view.decision.sand;

import java.util.List;

import scau.erps.app.Erps;
import scau.erps.entity.Loan;
import scau.erps.entity.Team;
import scau.erps.service.LoanService;
import scau.erps.service.impl.LoanServiceImpl;
import scau.erps.util.CalculateQuarter;

/**
 * 短贷盘面模拟面板
 * @author DCJ
 *
 */
public class ShortLoanPanel extends SandPanelTemplateFor4Q{
	private static final long serialVersionUID = 1L;
	public ShortLoanPanel(){
		super();
		this.titleLabel.setText("短贷");
		this.setTextFieldValue();		
	}
	@Override
	public void setTextFieldValue() {
		Team team = Erps.getCurrentTeam();
		int team_Id = team.getId();
		int q1 = 0;
		int q2 = 0;
		int q3 = 0;
		int q4 = 0;
		LoanService loanService = Erps.getIocInstance().get(LoanServiceImpl.class);
		List<Loan> shortLoans =loanService.getLoans(team_Id, "短贷", "已审核"); 
		for (Loan loan : shortLoans) {
			String endQuarter = loan.getEndTime();
			String currentQuarter = Erps.getSand().getTime();
			int step=Integer.parseInt(Erps.getSand().getStep());
			int quarter = CalculateQuarter.getQuarter(endQuarter,currentQuarter);
			if (CalculateQuarter.getCurrentYear(currentQuarter).equals("Y0"))
			if (step<=6) quarter++;                               
			int amount = loan.getAmount(); 
				if(quarter==1){
					q1=q1+amount;
				} 
				else if(quarter==2){
					q2=q2+amount; 
				}
				else if(quarter==3){
					q3=q3+amount;
				}
				else if(quarter==4){
					q4=q4+amount;
				}				
			}
			this.jtx_1q.setText(Integer.toString(q1));
			this.jtx_2q.setText(Integer.toString(q2));
			this.jtx_3q.setText(Integer.toString(q3));
			this.jtx_4q.setText(Integer.toString(q4));		
	}
}
